/*              Copyright(c) 2008 Dave Sexton              *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;

namespace DaveSexton.Sandcastle
{
	public struct QueryParameter : IEquatable<QueryParameter>
	{
		#region Public Properties
		public static readonly QueryParameter Empty = new QueryParameter();

		public DatabaseParameterSourceType Source
		{
			get
			{
				return source;
			}
		}

		public string ParameterName
		{
			get
			{
				return parameterName;
			}
		}

		public string ParameterValue
		{
			get
			{
				return parameterValue;
			}
		}
		#endregion

		#region Private / Protected
		private readonly DatabaseParameterSourceType source;
		private readonly string parameterName, parameterValue;
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="QueryParameter" /> structure.
		/// </summary>
		public QueryParameter(string parameterName, string parameterValue, DatabaseParameterSourceType source)
		{
			this.parameterName = parameterName;
			this.parameterValue = parameterValue;
			this.source = source;
		}
		#endregion

		#region Methods
		public override bool Equals(object obj)
		{
			return obj is QueryParameter && Equals((QueryParameter) obj);
		}

		public bool Equals(QueryParameter other)
		{
			return string.Equals(other.parameterName, parameterName, StringComparison.OrdinalIgnoreCase);
		}

		public override int GetHashCode()
		{
			return (parameterName ?? "").GetHashCode();
		}
		#endregion

		#region Operator Overloads
		public static bool operator ==(QueryParameter parameter1, QueryParameter parameter2)
		{
			return parameter1.Equals(parameter2);
		}

		public static bool operator !=(QueryParameter parameter1, QueryParameter parameter2)
		{
			return !parameter1.Equals(parameter2);
		}
		#endregion
	}
}
